package com.wc.算法基础课.D第四讲数学知识.矩阵乘法.垒骰子;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/4/5 10:24
 * @description https://www.acwing.com/problem/content/1219/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 7;
    static long[][] matrix = new long[N][N];
    static int P = (int) 1e9 + 7;
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i <= 6; i++) {
            Arrays.fill(matrix[i], 1);
        }
        // 我们记录朝上
        while (m-- > 0) {
            int x, y;
            x = sc.nextInt();
            y = sc.nextInt();
            int opX = x <= 3 ? x + 3 : x - 3;
            int opY = y <= 3 ? y + 3 : y - 3;
            matrix[opX][y] = 0;
            matrix[opY][x] = 0;
        }
        long[][] mat = qkmM(matrix, n - 1);
        long res = 0;
        for (int i = 1; i <= 6; i++) {
            for (int j = 1; j <= 6; j++) {
                res = (res + mat[i][j]) % P;
            }
        }
        out.println(res * qkm(4, n) % P);
        out.flush();
    }

    static long[][] qkmM(long[][] a, int b) {
        long[][] res = new long[7][7];
        for (int i = 1; i <= 6; i++) {
            res[i][i] = 1;
        }
        while (b > 0) {
            if ((b & 1) == 1) res = mulMatrix(res, a);
            a = mulMatrix(a, a);
            b >>= 1;
        }
        return res;
    }

    static long qkm(long a, int b) {
        long res = 1;
        while (b > 0) {
            if ((b & 1) == 1) res = res * a % P;
            a = a * a % P;
            b >>= 1;
        }
        return res;
    }

    static long[][] mulMatrix(long[][] a, long[][] b) {
        long[][] res = new long[7][7];
        for (int i = 1; i <= 6; i++) {
            for (int j = 1; j <= 6; j++) {
                for (int k = 1; k <= 6; k++) {
                    res[i][j] = (res[i][j] + a[i][k] * b[k][j]) % P;
                }
            }
        }
        return res;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}